import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter } from '@/utils/formatTime'

// 表单校验
export const rules = reactive({
  resId: [required],
})

// CrudSchema https://doc.iocoder.cn/vue3/crud-schema/
const crudSchemas = reactive<CrudSchema[]>([
  {
    label: 'id',
    field: 'id',
    isForm: false,
  },
  {
    label: '名称',
    field: 'title',
    isSearch: true,
  },
  {
    label: '别名',
    field: 'alias',
    isSearch: true,
  },
  {
    label: '原始版本Id',
    field: 'resId',
    isSearch: true,
    form: {
      component: 'InputNumber',
      value: 0
    },
  },
  {
    label: '关联表单设计ID',
    field: 'formDsgnId',
    isSearch: true,
    form: {
      component: 'InputNumber',
      value: 0
    },
  },
  {
    label: '关联流程设计ID',
    field: 'flowDsgnId',
    isSearch: true,
    form: {
      component: 'InputNumber',
      value: 0
    },
  },
  {
    label: '应用类别（0:表单应用;1:流程表单应用;2:页面应用;3:...）',
    field: 'mode',
    isSearch: true,
    form: {
      component: 'InputNumber',
      value: 0
    },
  },
  {
    label: '应用图标',
    field: 'icon',
    isSearch: true,
  },
  {
    label: '版本',
    field: 'version',
    isSearch: true,
    form: {
      component: 'InputNumber',
      value: 0
    },
  },
  {
    label: '创建时间',
    field: 'createTime',
    formatter: dateFormatter,
    isSearch: true,
    search: {
      component: 'DatePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        type: 'daterange',
        defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
      }
    },
    isForm: false,
  },
  {
    label: '应用描述',
    field: 'remark',
    isSearch: true,
  },
  {
    label: '发布时间',
    field: 'releaseTime',
    formatter: dateFormatter,
    isSearch: true,
    search: {
      component: 'DatePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        type: 'daterange',
        defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
      }
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        type: 'datetime',
        valueFormat: 'x'
      }
    },
  },
  {
    label: '状态',
    field: 'status',
    isSearch: true,
    form: {
      component: 'Radio'
    },
  },
  {
    label: '创建部门',
    field: 'createDept',
    isSearch: true,
    form: {
      component: 'InputNumber',
      value: 0
    },
  },
  {
    label: '发布状态（1:待发布；2：已发布）',
    field: 'deployState',
    isSearch: true,
    form: {
      component: 'InputNumber',
      value: 0
    },
  },
  {
    label: '维护状态(0:上架；1:下架)',
    field: 'maintState',
    isSearch: true,
    form: {
      component: 'InputNumber',
      value: 0
    },
  },
  {
    label: '应用维护者、拥有者',
    field: 'ownerUser',
    isSearch: true,
  },
  {
    label: '触发模式（0：工作表触发:1：定时触发；2：按照日期字段触发；3：组织人员事件触发；4：外部用户事件触发；5：Webhook触发）',
    field: 'triggerMode',
    isSearch: true,
    form: {
      component: 'InputNumber',
      value: 0
    },
  },
  {
    label: '操作',
    field: 'action',
    isForm: false
  }
])
export const { allSchemas } = useCrudSchemas(crudSchemas)